#include <iostream>
#include <string>
#include "Game.h"

using namespace std;





/**
 * Prints a Menu where the Player can either Fight or Retreat
 * TODO: add Magical Spells in this section
 * @param Monster* newMonster - the monster to fight
 * @return char - returns the choice of the Player
 */
char Game::printFightMenu(Monster* newMonster)
{
	char choice;

	if (newMonster == 0)
		return 0;
	cout << endl << endl;
	cout << "-||==>> * -||==>> * -||==>> * -||==>> * -||==>> *" << endl << endl;
	cout << "A " << newMonster->getName() << " stands in front of you." << endl;
	cout << endl << endl;
	cout << m_player->getName() << "'s HP: " << m_player->getHP() << "/" << m_player->getMaxHP() << endl;
	cout << newMonster->getName() << "'s HP: " << newMonster->getHP() << "/" << newMonster->getMaxHP() << endl << endl;
	cout << " What do you want to do?" << endl;
	cout << "- [F]ight" << endl;
	cout << "- [R]etreat" << endl;
	cout << endl;
	cout << "Your choice: ";
	cin >> choice;
	system("cls");
	return choice;
}


/**
 * Process the choice of the player.
 * @see processFight()
 * @see processFlee()
 * @see printFightMenu()
 * @see newEncounter()
 * @param char choice - choice of the player
 * @param Monster* newMonster - the monster to fight
 * @return bool - false if the choice is not correct or (Player or Monster are not dead)
 */
bool Game::processFightMenu(char choice, Monster* newMonster)
{
	if (newMonster != 0)
	{
		switch (choice)
		{
		case 'f':
		case 'F':
			return (processFight(newMonster));
			break;
		case 'r':
		case 'R':
			return (processFlee(newMonster));
			break;
		default:
			break;
		}
	}
	return false;
}


/**
 * A round of attack is calculated.
 * If the monster is dead the player receives gold and experience
 * If the player is dead the monster receives nothing but the game is over
 * @param Monster* newMonster - the monster to fight
 * @return bool - true if one of the protagonist is dead
 */
bool Game::processFight(Monster* newMonster)
{
	m_player->attack(*newMonster);
	if (newMonster->isDead())
	{
		m_player->addGold(newMonster->getGold());
		m_player->addXP(newMonster->getXP());
		if ((m_vecMaxXPperLevel.size() > (m_player->getLevel() + 1)) &&
			(m_player->getXP() >= m_vecMaxXPperLevel[m_player->getLevel()]))
		{
			m_player->levelUp();
		}
		cout << m_player->getName() << " has killed " << newMonster->getName() << endl;
		m_iState = GAME_STATE_PLAY;
		return true;
	}
	newMonster->attack(*m_player);
	if (m_player->isDead())
	{
		cout << newMonster->getName() << " has killed " << m_player->getName() << endl;
		GameOver();
		return true;
	}
	return false;
}


/**
 * The player flees and the monster has one last attack
 * @param Monster* newMonster - the monster to fight
 * @return bool - always true
 */
bool Game::processFlee(Monster* newMonster)
{
	newMonster->attack(*m_player);
	if (m_player->isDead())
	{
		GameOver();
	}
	else
	{
		m_iState = GAME_STATE_MOVE;
	}
	return true;
}
